package com.wx.chapter10.static_;

import java.nio.charset.MalformedInputException;

/**
 * ClassName:StaticMethod
 * Package :com.wx.chapter10.static_
 * Description :
 *
 * @Author : coder_mu
 * @Create : 2023/6/2 - 15:55
 */
public class StaticMethod {
    public static void main(String[] args) {
        Stu tom = new Stu("tom");
        tom.payFee(100);
        Stu mary = new Stu("mary");
        mary.payFee(200);

        //输出当前收到的总学费
        Stu.showFee();//类名可以直接调用静态方法，如果方法不加static，则不能调用

        System.out.println(MyTools.calSum(1, 2));
    }
}

class Stu {
    private String name;//普通成员变量
    private static double fee = 0;//静态成员变量

    //静态方法
    public static void payFee(double fee) {
        Stu.fee += fee;//类名调用静态变量
    }

    public static void showFee() {
        System.out.println("总学费有:" + Stu.fee);
    }

    //构造器
    public Stu(String name) {
        this.name = name;
    }
}

class MyTools {
    //求出两个数的和
    public static double calSum(double n1, double n2) {
        return n1 + n2;
    }
}